package com.example.sourcecodelearning.modules.statemachine.listener;

import com.example.sourcecodelearning.modules.statemachine.Event;
import com.example.sourcecodelearning.modules.statemachine.States;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;

/**
 * 另一种写法参考{@link StateMachineListener}
 */
public class BasketballMusicStateMachineEventListener extends StateMachineListenerAdapter<States, Event> {

    @Override
    public void stateChanged(State<States, Event> from, State<States, Event> to) {
        if (from != null && to != null) {
            if (from.getId() == States.IDLE && to.getId() == States.PLAYING_BB) {
                System.out.println("开始打篮球，music 起");
            } else if (from.getId() == States.PLAYING_BB && to.getId() == States.SINGING) {
                System.out.println("唱跳，你干嘛");
            } else if (from.getId() == States.SINGING && to.getId() == States.PLAYING_BB) {
                System.out.println("继续打篮球，music 继续");
            }
        }
    }
}
